package com.fastloan.mgt.application.approve.controller;

import com.alibaba.fastjson.JSONObject;
import com.fastloan.core.kuaixin.baidu.BaiDuModel;
import com.fastloan.mgt.application.approve.model.ApplicationApprove;
import com.fastloan.mgt.application.approve.model.ApplicationApproveHistory;
import com.fastloan.mgt.application.approve.service.ApplicationApproveHistoryService;
import com.fastloan.mgt.application.approve.service.ApplicationApproveService;
import com.fastloan.mgt.log.aspect.SystemLog;
import com.fastloan.safe.core.util.ManagerKit;
import com.kawins.base.baseabs.BaseController;
import com.kawins.result.ResultTo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * @author chenkai
 * createTime 2017-11-2017/11/9 10:48
 */
@RestController
@RequestMapping("/api/web/applicationApprove")
public class ApplicationApproveController extends BaseController<ApplicationApprove> {
    @Autowired
    private ApplicationApproveService applicationApproveService;

    @Autowired
    private ApplicationApproveHistoryService applicationApproveHistoryService;

    /**
     * 查询审批列表
     *
     * @return
     */
    @RequestMapping("/pageList")
    public ResultTo pageList() {
        Map<String, Object> map = new HashMap<>();
        map.put("userId", ManagerKit.getUserId());
        return dataPage("queryAppApproveList", map);
    }

    /**
     * 提交审批
     *
     * @param applicationApprove
     * @return
     */
    @PostMapping
    @SystemLog(description="提交审批")
    public ResultTo submitApprove(ApplicationApprove applicationApprove) {
        applicationApproveService.submitApprove(applicationApprove);
        return new ResultTo();
    }

    /**
     * 获取审批详情
     *
     * @param applicationApproveId
     * @return
     */
    @GetMapping("/{applicationApproveId}")
    public ResultTo getAppApproveInfo(@PathVariable String applicationApproveId) {
        return new ResultTo().setData(applicationApproveService.queryApplicationApprove(applicationApproveId));
    }

    /**
     * 查看审批计划
     *
     * @param applicationId
     * @return
     */
    @GetMapping("/plan/{applicationId}")
    public ResultTo getAppApprovePlan(@PathVariable String applicationId) {
        return new ResultTo().setData(applicationApproveService.queryApprovePlan(applicationId));
    }

    /**
     * 查看审批历史
     *
     * @param applicationId
     * @return
     */
    @GetMapping("/history/{applicationId}")
    public ResultTo getHistoryAppApproveInfo(@PathVariable String applicationId) {
        return new ResultTo().setData(applicationApproveHistoryService.queryApproveHistory(applicationId));
    }

    /**
     * 查看审批历史分页
     *
     * @return
     */
    @RequestMapping("/history/pageList")
    public ResultTo getHistoryAppApprovePageList() {
        return dataPage(applicationApproveHistoryService, ApplicationApproveHistory.class, "queryApproveHistoryPageList");
    }

    @GetMapping("/test")
    public ResultTo test(String name, String idCard, String phone) {
        return new ResultTo().setData("multiScore", JSONObject.toJSONString(BaiDuModel.multiScore(name, idCard, phone)))
                .setData("blackScore", JSONObject.toJSONString(BaiDuModel.blackScore(name, idCard, phone)))
                .setData("risk", JSONObject.toJSONString(BaiDuModel.risk(name, idCard, phone)));
    }

}

